<template>
	<view>
		<!-- 功能列表 -->
		<my-list :list="list" 
			@setWifiPlay="setWifiPlay"
			@setWifiDownload="setWifiDownload"
			@setAutoPlay="setAutoPlay"
			@clearStorage="clearStorage"
		/>
	</view>
</template>

<script>
	import list from '@/config/setting-list-bar.js'
	export default {
		data() {
			return {
				list:list()
			}
		},
		methods: {
			
			//抽取公共部分，存储到本地存储
			saveStorage(obj,key){
				const checked = !obj.checked
				console.log(checked);
				this.$set(obj,'checked',checked)
				uni.setStorage({
					key,
					data:checked
				})
			},
			
			//设置非wifi播放
			setWifiPlay(obj){
				this.saveStorage(obj,'wifi-play')
			},
			//设置非wifi缓存
			setWifiDownload(obj){
				this.saveStorage(obj,'wifi-download')
			},
			//设置自动播放
			setAutoPlay(obj){
				this.saveStorage(obj,'auto-play')
			},
			//清除缓存
			clearStorage(obj){
				uni.showModal({
					title:'你确定要清除缓存吗？',
					content:'(该操作不会删除缓存课程)',
					success: (res) => {
						if(res.confirm){
							//清空缓存
							uni.clearStorage()
							//清空赋值
							this.$set(obj,'text','0KB')
							this.$util.msg('清除成功')
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss">
page {
		background-color: $mxg-color-grey;
	}
</style>
